<?php

class m110807_083253_create_reference extends CDbMigration {

	protected $_tables = array(
		'reference'=>array(
			'_id'=>'pk',
			'name'=>'string',
			'value'=>'string',
		),
	);
	protected $_indexes = array(
		'reference'=>array(
			'name',
		),
	);

	public function safeUp() {
		foreach ($this->_tables as $key=>$value) {
			$this->createTable($key, $value);
		}
		foreach ($this->_indexes as $table=>$columns) {
			foreach ($columns as $column) {
				$name = 'idx_' . $table . '_' . $column;
				$this->createIndex($name, $table, $column);
			}
		}
	}

	public function safeDown() {
		foreach ($this->_indexes as $table=>$columns) {
			foreach ($columns as $column) {
				$name = 'idx_' . $table . '_' . $column;
				$this->dropIndex($name, $table, $column);
			}
		}
		foreach ($this->_tables as $key=>$value) {
			$this->dropTable($key);
		}
	}

}